
package hpiC77Lt . rfuqv8zt ;

final class RevelationApplication
{
    private static final java . lang . String PASSWORD = "password" ;

    private static final java . util . Random RANDOM = new java . util . Random ( ) ;

    private static final java . lang . String GENERICPASSWORD = "generic-password" ;

    private static final int BYTESIZE = 256 ;

    public static final void main ( final java . lang . String [ ] args ) throws java . lang . Exception
    {
	final javax . xml . parsers . DocumentBuilderFactory factory = javax . xml . parsers . DocumentBuilderFactory . newInstance ( ) ;
	final javax . xml . parsers . DocumentBuilder builder = factory . newDocumentBuilder ( ) ;
	final java . lang . String inputFileName = args [ 0 ] ;
	final java . io . File inputFile = new java . io . File ( inputFileName ) ;
	final org . w3c . dom . Document input = builder . parse ( inputFile ) ;
	final org . w3c . dom . Document left = builder . newDocument ( ) ;
	final org . w3c . dom . Document right = builder . newDocument ( ) ;
	visitChildren ( input , left , left , right , right , false ) ;
	write ( left , args [ 1 ] ) ;
	write ( right , args [ 2 ] ) ;
    }

    private static final void visitChildren ( final org . w3c . dom . Node input , final org . w3c . dom . Document leftDocument , final org . w3c . dom . Node left , final org . w3c . dom . Document rightDocument , final org . w3c . dom . Node right , final boolean otp )
    {
	final org . w3c . dom . NodeList childNodes = input . getChildNodes ( ) ;
	final int length = childNodes . getLength ( ) ;
	for ( int i = 0 ; i < length ; i ++ )
	    {
		final org . w3c . dom . Node child = childNodes . item ( i ) ;
		visit ( child , leftDocument , left , rightDocument , right , otp ) ;
	    }
	final org . w3c . dom . NamedNodeMap attributes = input . getAttributes ( ) ;
	if ( attributes != null )
	    {
		final int attributeCount = attributes . getLength ( ) ;
		for ( int i = 0 ; i < attributeCount ; i ++ )
		    {
			final org . w3c . dom . Node attribute = attributes . item ( i ) ;
			visit ( attribute , leftDocument , left , rightDocument , right , otp ) ;
		    }
	    }
    }

    private static final void visit ( final org . w3c . dom . Node input , final org . w3c . dom . Document leftDocument , final org . w3c . dom . Node left , final org . w3c . dom . Document rightDocument , final org . w3c . dom . Node right , boolean otp )
    {
	if ( input instanceof org . w3c . dom . Attr )
	    {
		final org . w3c . dom . Attr i = ( org . w3c . dom . Attr ) ( input ) ;
		final java . lang . String name = i . getName ( ) ;
		final org . w3c . dom . Attr l = leftDocument . createAttribute ( name ) ;
		final org . w3c . dom . Attr r = rightDocument . createAttribute ( name ) ;
		final java . lang . String value = i . getValue ( ) ;
		final boolean password = name . contains ( PASSWORD ) ;
		if ( password )
		    {
			otp = true ;
		    }
		else
		    {
			l . setValue ( value ) ;
			r . setValue ( value ) ;
		    }
		//		visitChildren ( i , leftDocument , l , rightDocument , r , otp ) ;
		setAttributeNode ( left , l ) ;
		setAttributeNode ( right , r ) ;
	    }
	else if ( input instanceof org . w3c . dom . CharacterData )
	    {
		final org . w3c . dom . CharacterData i = ( org . w3c . dom . CharacterData ) ( input ) ;
		final org . w3c . dom . Node p = i . getParentNode ( ) ;
		final org . w3c . dom . NodeList cl = p . getChildNodes ( ) ;
		final int cs = cl . getLength ( ) ;
		if ( cs == 1 )
		    {
			final java . lang . String data = i . getData ( ) ;
			final org . w3c . dom . CDATASection l = leftDocument . createCDATASection ( data ) ;
			final org . w3c . dom . CDATASection r = rightDocument . createCDATASection ( data ) ;
			final org . w3c . dom . Node parentNode = i . getParentNode ( ) ;
			final org . w3c . dom . NamedNodeMap ats = parentNode . getAttributes ( ) ;
			final org . w3c . dom . Node idAttr = ats . getNamedItem ( "id" ) ;
			if ( idAttr != null )
			    {
				final java . lang . String idVal = idAttr . getNodeValue ( ) ;
				if ( idVal . equals ( GENERICPASSWORD ) )
				    {
					otp ( i , l , r ) ;
				    }
			    }
			otp = false ;
			left . appendChild ( l ) ;
			right . appendChild ( r ) ;
		    }
	    }
	else if ( input instanceof org . w3c . dom . Comment )
	    {
		final org . w3c . dom . Comment i = ( org . w3c . dom . Comment ) ( input ) ;
		final java . lang . String data = i . getData ( ) ;
		final org . w3c . dom . Comment l = leftDocument . createComment ( data ) ;
		final org . w3c . dom . Comment r = rightDocument . createComment ( data ) ;
		visitChildren ( i , leftDocument , l , rightDocument , r , otp ) ;
		left . appendChild ( l ) ;
		right . appendChild ( r ) ;
	    }
	else if ( input instanceof org . w3c . dom . Element )
	    {
		final org . w3c . dom . Element i = ( org . w3c . dom . Element ) ( input ) ;
		final java . lang . String tagName = i . getTagName ( ) ;
		final org . w3c . dom . Element l = leftDocument . createElement ( tagName ) ;
		final org . w3c . dom . Element r = rightDocument . createElement ( tagName ) ;
		visitChildren ( i , leftDocument , l , rightDocument , r , otp ) ;
		left . appendChild ( l ) ;
		right . appendChild ( r ) ;
	    }
    }

    private static final void otp ( final org . w3c . dom . CharacterData input , final org . w3c . dom . CharacterData left , final org . w3c . dom . CharacterData right )
    {
	final java . lang . String value = input . getData ( ) ;
	final java . lang . StringBuffer lBuffer = new java . lang . StringBuffer ( ) ;
	final java . lang . StringBuffer rBuffer = new java . lang . StringBuffer ( ) ;
	final byte [ ] bytes = value . getBytes ( ) ;
	for ( final int b : bytes )
	    {
		final int lll = RANDOM . nextInt ( BYTESIZE ) ;
		final int ll = lll % 15 + 1 ;
		final int l = ll * BYTESIZE + lll ;
		final java . lang . String lHex = java . lang . Integer . toHexString ( l ) ;
		lBuffer . append ( lHex ) ;
		final int rrr = ( BYTESIZE + b - lll ) % BYTESIZE ;
		final int rr = rrr % 15 + 1 ;
		final int r = rr * BYTESIZE + rrr ;
		final java . lang . String rHex = java . lang . Integer . toHexString ( r ) ;
		rBuffer . append ( rHex ) ;
	    }
	final java . lang . String lString = lBuffer . toString ( ) ;
	left . setData ( lString ) ;
	final java . lang . String rString = rBuffer . toString ( ) ;
	right . setData ( rString ) ;
	final int lLength = lString . length ( ) ;
	final int rLength = rString . length ( ) ;
	assert lString . length ( ) == rString . length ( ) : "The two strings are note equal lenght." ;
    }

    private static final void setAttributeNode ( final org . w3c . dom . Node node , final org . w3c . dom . Attr attribute )
    {
	if ( node instanceof org . w3c . dom . Element )
	    {
		final org . w3c . dom . Element element = ( org . w3c . dom . Element ) ( node ) ;
		element . setAttributeNode ( attribute ) ;
	    }
    }

    private static final void write ( final org . w3c . dom . Document document , final java . lang . String fileName ) throws java . io . IOException
    {
	final java . io . File file = new java . io . File ( fileName ) ;
	final java . io . Writer writer = new java . io . FileWriter ( file ) ;
	write ( document , writer , "" ) ;
	writer . close ( ) ;
    }

    private static final void write ( final org . w3c . dom . Node node , final java . io . Writer writer , final java . lang . String indent ) throws java . io . IOException
    {
	if ( node instanceof org . w3c . dom . Attr )
	    {
		final org . w3c . dom . Attr i = ( org . w3c . dom . Attr ) ( node ) ;
		writer . write ( " " ) ;
		final java . lang . String name = i . getName ( ) ;
		writer . write ( name ) ;
		final java . lang . String value = i . getValue ( ) ;
		writer . write ( "=\"" ) ;
		writer . write ( value ) ;
		writer . write ( "\"" ) ;
	    }
	else if ( node instanceof org . w3c . dom . Element )
	    {
		final org . w3c . dom . Element i = ( org . w3c . dom . Element ) ( node ) ;
		final java . lang . String tagName = i . getTagName ( ) ;
		writer . write ( "\n" ) ;
		writer . write ( indent ) ;
		writer . write ( "<" ) ;
		writer . write ( tagName ) ;
		final org . w3c . dom . NamedNodeMap attributes = i . getAttributes ( ) ;
		final int attributeCount = attributes . getLength ( ) ;
		for ( int j = 0 ; j < attributeCount ; j ++ )
		    {
			final org . w3c . dom . Node attribute = attributes . item ( j ) ;
			write ( attribute , writer , indent ) ;
		    }
		writer . write ( ">" ) ;
		final org . w3c . dom . NodeList childNodes = i . getChildNodes ( ) ;
		final int childCount = childNodes . getLength ( ) ;
		for ( int j = 0 ; j < childCount ; j ++ )
		    {
			final org . w3c . dom . Node child = childNodes . item ( j ) ;
			write ( child , writer , indent + " " ) ;
		    }
		writer . write ( "</" ) ;
		writer . write ( tagName ) ;
		writer . write ( ">" ) ;
	    }
	else if ( node instanceof org . w3c . dom . CDATASection )
	    {
		final org . w3c . dom . CDATASection i = ( org . w3c . dom . CDATASection ) ( node ) ;
		final java . lang . String data = i . getData ( ) ;
		writer . write ( data ) ;
	    }
	else if ( node instanceof org . w3c . dom . Document )
	    {
		final org . w3c . dom . NodeList childNodes = node . getChildNodes ( ) ;
		final int childCount = childNodes . getLength ( ) ;
		for ( int i = 0 ; i < childCount ; i ++ )
		    {
			final org . w3c . dom . Node child = childNodes . item ( i ) ;
			write ( child , writer , "" ) ;
		    }		
	    }
    }
}